/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package beans;

import database_beans.Projekti;
import java.io.Serializable;
import java.util.ArrayList;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;
import server.Util;

/**
 *
 * @author stefan
 */
@ManagedBean
@RequestScoped
public class Projekat implements Serializable {

    private ArrayList<Projekti> projekti;

    /**
     * Creates a new instance of ProjekatBean
     */
    public Projekat() {
        
    }
    
    @PostConstruct
    public void init(){
        loadProjekti();
    }

    public ArrayList<Projekti> getProjekti() {
        return projekti;
    }

    public void setProjekti(ArrayList<Projekti> projekti) {
        this.projekti = projekti;
    }

    public void loadProjekti() {
        Session session = Util.getSesion();
        Transaction t = session.beginTransaction();
        try {
            Criteria c = session.createCriteria(Projekti.class);
            projekti = new ArrayList<Projekti>((ArrayList<Projekti>) c.list());
            t.commit();
        } catch (Exception e) {
            t.rollback();
        }
    }

}
